<!doctype html>
<html lang="zh-cn">
<head>
{% include "tdm_include_head_template.html" %}

<script type="text/javascript">
$(function() {
  sidebar_nav_clone();
  //$('.collapse').collapse('hide');
  var item_div_id = [];
  var item_div_type = [];
  {% for item_name, type in item_name_list %}
  item_div_id.push('{{item_name}}');
  item_div_type.push('{{type}}');
  {% endfor %}

  $.each(item_div_id, function(i, n) {
    $.getJSON(server_id_to_url(n, '/json/server_item_warn_alert/'), function (data) {
      var item_warn_alert = '';
      if (data.alert_nr) {
        item_warn_alert+='<div class="pull-right"><span class="badge badge-danger">'+data.alert_nr+'</span></div>';
      }
      if (data.warn_nr) {
        item_warn_alert+='<div class="pull-right"><span class="badge badge-warning">'+data.warn_nr+'</span></div>';
      }
      $(flot_id_translate(n, '')).html('<a href="'+id_to_url(n, '/view/server_item/')+'">'+item_name_show(n)+item_warn_alert+'</a>');
    });

    var req_time = {};
    if (item_div_type[i] == 'column') {
      req_time = { req_time: "2880" };  /* 60*24*2 2 day */
    }

    $.getJSON(server_id_to_url(n, '/json/server_item_data/'), req_time, function (data) {
        //alert('n=' + n + item_div_type[i]);
        if (item_div_type[i] == 'port') {
          port_update_table(flot_id_translate(n, '_table'), data);
        } else if (item_div_type[i] == 'file') {
          file_update_table(flot_id_translate(n, '_table'), data);
        } else if (item_div_type[i] == 'diskload') {
          pie_show(flot_id_translate(n, '_flot'), data);
        } else if (item_div_type[i] == 'column') {
          column_show(flot_id_translate(n, '_flot'), data);
        } else {
          spline_show(flot_id_translate(n, '_flot'), data);
        }
    });
  });
  Highcharts.setOptions({global:{useUTC : false}});
});
</script>

</head>

<body class=" theme-blue">
{% include "tdm_include_navbar_template.html" %}

<div class="sidebar-nav">
  <ul id="city_jxd">
  {% for city in jxd_list_all %}
  <li>
    <a href="#" data-target=".{{city.name}}-menu" class="nav-header collapsed" data-toggle="collapse" aria-expanded="false">
      <i class="fa fa-fw fa-bars"></i>
      {{city.name}}
      {% if city.warning_nr %}
      <span class="badge badge-warning">{{city.warning_nr}}</span>
      {% endif %}
      {% if city.alert_nr %}
      <span class="badge badge-danger">{{city.alert_nr}}</span>
      {% endif %}
      <i class="fa fa-collapse"></i>
    </a>
  </li>
  <li>
    <ul class="{{city.name}}-menu nav nav-list collapse {% ifequal view_city city.name %}in{% endifequal %}">
      {% for jxd in city.jxd_list %}
      <li>
        <a href="/view/server/{{city.name}}/{{jxd.name}}">
          <span class="fa fa-caret-right"></span>
          {{jxd.name}}
          {% if jxd.warning_nr %}
          <div class="pull-right">
            <span class="badge badge-warning">{{jxd.warning_nr}}</span>
          </div>
          {% endif %}
          {% if jxd.alert_nr %}
          <div class="pull-right">
            <span class="badge badge-danger">{{jxd.alert_nr}}</span>
          </div>
          {% endif %}
        </a>
      </li>
      {% endfor %}
    </ul>
  </li>
  {% endfor %}
  </ul>
</div>

<div class="content">
  <div class="header">
    <a class="btn btn-primary btn-jxd" rol="button" href="/view/server/{{view_city}}/{{view_jxd}}/">
      {{view_city}} - {{view_jxd}}
      <span class="glyphicon glyphicon-circle-arrow-right"></span>
    </a>
    <ul class="nav nav-tabs" role="tablist">
      {% for server in server_list %}
      <li role="presentation" {% ifequal server.name view_server %}class="active"{% endifequal %}>
        <a href="/view/server/{{view_city}}/{{view_jxd}}/{{server.name}}">{{server.name}}
        {% if server.warning_nr %}
        <span class="badge badge-warning">{{server.warning_nr}}</span>
        {% endif %}
        {% if server.alert_nr %}
        <span class="badge badge-danger">{{server.alert_nr}}</span>
        {% endif %}
        </a>
      </li>
      {% endfor %}
    </ul>
    <!--
    <ol class="breadcrumb">
    {% for type in server_item_type_list %}
      <li>
        <a href="/view/server/{{req_city}}/{{req_jxd}}/{{type}}">{{type}}</a>
      </li>
    {% endfor %}
    </ol>
    -->
  </div>
  <div class="table-responsive">
    <table class="table table-hover">
      <tr>
        <th>hostname</th>
        <th>IP address</th>
        <th>Online</th>
        <th>CPU Load</th>
        <th>MEM Load</th>
        <th>Process</th>
      </tr>
      {% for server in server_list %}
      <tr>
        <td>{{server.name}}</td>
        <td>{{server.ipaddr}}</td>
        <td>{{server.online}}</td>
        <td>{{server.cpuload}}</td>
        <td>{{server.memload}}</td>
        <td>{{server.procnr}}</td>
      </tr>
      {% endfor %}
      {% if server_list|length_is:"0" %}
      <tr><td colspan="6" align="center">无服务器</td></tr>
      {% endif %}
    </table>
  </div>
  <div class="item-content">
    <div class="row">
    {% for item_name, type in item_name_list %}
    <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
    <div class="panel panel-default panel-fix-280">
      <div id='{{item_name}}' class="panel-heading">{{item_name}}</div>
      {% if type == 'port' %}
      <table id="{{item_name}}_table" class="table">
        <tr><th>service</th><th>port</th><th>status</th></tr>
      </table>
      {% else %}
      {% if type == 'file' %}
      <table id="{{item_name}}_table" class="table">
        <tr><th>file</th><th>status</th></tr>
      </table>
      {% else %}
      <div id="page-stats" class="panel-body">
      <div id="content">
        <div id="{{item_name}}_flot" style="height: 200px; min-width: 300px"></div>
      </div>
      </div>
      {% endif %}
      {% endif %}
    </div>
    </div>
    {% endfor %}
    </div>

  {% include "tdm_include_footer_template.html" %}
  </div>
</div>
</body>
</html>